package com.liuchuanzheng.lcz_viewmove;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.Scroller;

import com.google.android.material.internal.ViewUtils;

public class ScrollerLayout extends androidx.appcompat.widget.AppCompatTextView {
    private Scroller mScroller;
 
    public ScrollerLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        mScroller = new Scroller(context);
    }
 
    @Override
    public void computeScroll() {
        super.computeScroll();
        if(mScroller.computeScrollOffset()) {
            scrollTo( mScroller.getCurrX(), mScroller.getCurrY());
            invalidate();
        }
    }
 
    @SuppressLint("RestrictedApi")
    public void start_scroll() {
        mScroller.startScroll(getScrollX(), getScrollY(), (int) ViewUtils.dpToPx(getContext(),-20), getScrollY(), 3000);
        invalidate();
    }
}